package com.yzf.enterprise.project.controller;

import com.alibaba.fastjson.JSONObject;
import org.apache.tika.Tika;
import org.apache.tika.metadata.Metadata;
import org.apache.tika.utils.ParserUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.io.*;

/**
 * @author wangzhen
 * @Description: ${todo}
 * @date 2020/9/18 16:27
 */
@Controller
public class TestController {

    @RequestMapping("test1")
    public String test1(){
        System.out.println("test1");
        return "test1";
    }

    public static void main(String[] args) throws Exception{
//        File file = new File("E:\\2.txt");
//        BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file),"UTF-8"));
//        String temp = "";
//        while ((temp = in.readLine()) != null) {
//            System.out.println(temp);
//        }
        //选择要提取的文件
        File file = new File("E:\\1.pdf");
        Tika tika = new Tika();
        Metadata metadata = new Metadata();
        metadata.set(Metadata.AUTHOR, "空号");//重新设置文档的媒体内容
        metadata.set(Metadata.RESOURCE_NAME_KEY, file.getName());
        String str = tika.parseToString(new FileInputStream(file),metadata);

        System.out.println(str);
        System.out.println("--------------------------------------");
        JSONObject obj = JSONObject.parseObject(str);
        System.out.println(obj);



    }
}
